#!usr/bin/env python
# -*- coding:utf-8 -*-
# user nanme: Mr.zhang
# data time : 2022/9/16   6:48 下午
# project   : func_Tools.py
# IDE       : PyCharm
# email     :17600960626@163.com
import json
import os
import re
import time

from conftest import driver
from lib.func import think_time
from public.public_Method import BasePage
from lib.init_data import get_vm_size,get_path


class ZC_test(BasePage):


    def click_page(self):
        '''
        启动emptyinput并点击空白处
        '''
        self.star_app('com.xinmei365.emptyinput')
        return self.x_y_click(0.155, 0.565)


    def click_menu(self):
        '''点击menu'''
        # self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/entry_left_container"]/android.widget.RelativeLayout[1]/android.widget.ImageButton[1]')
        self.xpath_click('//*[@resource-id="kika.emoji.keyboard.teclados.clavier:id/entry_left_container"]/android.widget.RelativeLayout[1]/android.widget.ImageButton[1]')

    def turn_on_vibration(self,text):
        '''
        键盘弹出后，开启或关闭键盘震动
        text: 开启、关闭
        '''
        self.click_menu()
        if text == ['开启']:
            try:
                self.find_xpath('//*[@resource-id="kika.emoji.keyboard.teclados.clavier:id/off"]')
            except Exception as e:
                pass
            else:
                self.text_click('Vibrate')
        elif text ==['关闭']:
            try:
                self.find_xpath('//*[@resource-id="kika.emoji.keyboard.teclados.clavier:id/on"]')
            except Exception as e:
                pass
            else:
                self.text_click('Vibrate')
        self.back()


    def set_sound(self):
        '''进入muen，点击声音设置'''
        self.click_menu()
        self.text_click('Sound')

    def set_selector(self):
        '''进入muen，点击selector'''
        self.click_menu()
        self.text_click('Selector')

    def _selector_left(self):
        '''编辑页，左按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/iv_left"]')

    def _selector_right(self):
        '''编辑页，右按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/iv_right"]')

    def _selector_up(self):
        '''编辑页，上按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/iv_top"]')

    def _selector_down(self):
        '''编辑页，下按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/iv_bottom"]')

    def _selector_set(self):
        '''编辑页，单选按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/select"]')

    def _selector_much_set(self):
        '''编辑页，多选按扭'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/container1"]')

    def _selector_copy(self):
        '''编辑页，复制'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/container2"]')

    def _selector_paste(self):
        '''编辑页，粘贴'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/container3"]')

    def _selector_delete(self):
        '''编辑页，删除'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/container4"]')

    def set_clipboard(self):
        '''打开mune，进入剪贴板'''
        self.click_menu()
        self.text_click('ClipBoard')

    def clipboard_click(self):
        '''点击剪贴板开关按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/switch_clipboard_enable"]')

    def clipboard_delet(self):
        '''点击剪贴板删除'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/entry_right_container"]/android.widget.RelativeLayout[1]/android.widget.ImageButton[1]')

    def set_autocorrre(self):
        '''开启纠错'''
        self.click_menu()
        self.text_click('Auto-correction')

    def set_layout(self,text):
        '''设置键盘模式'''
        self.click_menu()
        self.scro_text_click('Layout')
        self.text_click(text)

    def one_handed_close(self):
        '''单手模式-关闭按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/one_hand_cancel"]')

    def one_handed_right(self):
        '''单手模式-箭头按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/one_hand_switch"]')

    def one_handed_size(self):
        '''唤醒可拖动按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/one_hand_size"]')

    def coor_keyboard_26(self,text,text1):
        '''获取字母坐标-26'''
        path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        path_name = path + '/layout/pro_26键'
        with open(path_name) as f:
            a = f.read()
            j = json.loads(a)
            for i in j["keys"]:
                if i['code'] == text:
                    for x in j["keys"]:
                        if x['code'] ==text1:
                            return i['x'], i['y'],x['x'],x['y']



    def long_keyboard_26(self,text):
        '''字母键盘长按-26'''
        path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        path_name = path + '/layout/pro_26键'
        with open(path_name) as f:
            a = f.read()
            j = json.loads(a)
            for i in j["keys"]:
                if i['code'] == text:
                    return self.long_clicks(i['x'], i['y'])



    def send_char_26(self,text):
        '''点击键盘字母按键-26'''
        path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        path_name = path + '/layout/pro_26键'
        with open(path_name) as f:
            a = f.read()
            j = json.loads(a)
            for i in j["keys"]:
                if i['code'] == text:
                    return self.x_y_click(i['x'], i['y'])

    def hove_char_26(self,text):
        '''点击悬浮键盘字母按键-26'''
        path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
        path_name = path + '/layout/pro_悬浮26键'
        with open(path_name) as f:
            a = f.read()
            j = json.loads(a)
            for i in j["keys"]:
                if i['code'] == text:
                    return self.x_y_click(i['x'], i['y'])

    def set_size(self):
        '''进入设置键盘大小页'''
        self.click_menu()
        self.scro_text_click('Size')

    def hover_drag(self):
        '''悬浮-拖动按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/float_mode_touch_view"]')

    def hover_size(self):
        '''悬浮-大小按钮'''
        self.xpath_click('//*[@resource-id="com.emoji.coolkeyboard:id/float_mode_size"]')





